<?php

use Carbon\Carbon;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        \App\Area::truncate();
        \App\Product::truncate();
        \App\Record::truncate();
        \App\Log::truncate();
        $time = '2018-12-29';
        $areas = [
            ['ie' => '869300034335566', 'ic' => '05107060075601013', 'lat' =>  31.34733, 'lng' =>   120.70461, 'name' =>   '吴中区园区葑亭大道与瑞华路交叉口' ,'area' => '江苏省'],
            ['ie' => '869300034336176', 'ic' => '05107060075601074', 'lat' =>  31.34687, 'lng' =>   120.72142, 'name' =>   '吴中区跨春路18号', 'area' => '江苏省'],
            ['ie' => '869300034335996', 'ic' => '05107060075601056', 'lat' =>  31.37586, 'lng' =>   120.73657, 'name' =>   '吴中区优步花园(水泽路西100米)','area' => '江苏省'],
            ['ie' => '869300034335871', 'ic' => '05107060075601044', 'lat' =>  31.36893, 'lng' =>   120.73821, 'name' =>   '江苏苏净集团公司','area' => '江苏省'],
            ['ie' => '869300034334619', 'ic' => '05107060075600918', 'lat' =>  32.032900, 'lng' =>  118.736065, 'name' =>  '南京万达广场（建邺店）' ,'area' => '江苏省'],
            ['ie' => '869300034334908', 'ic' => '05107060075600940', 'lat' =>  32.008500, 'lng' =>  118.707410, 'name' =>  '南京市排水管理所'    ,'area' => '江苏省'],
            ['ie' => '869300034336481', 'ic' => '05107060075601105', 'lat' =>  29.222149, 'lng' =>  121.9496, 'name' =>    '浙江省宁波市象山县渔丰苑','area' => '浙江省'],
            ['ie' => '869300034331078', 'ic' => '05107060075600564', 'lat' =>  29.222149, 'lng' =>  121.9496, 'name' =>    '浙江省宁波市象山县渔丰苑','area' => '浙江省'],
            ['ie' => '869300034335806', 'ic' => '05107060075601037', 'lat' =>  27.490000, 'lng' =>  114.530000, 'name' =>  '御秀山庄','area' => '江西省'],
            ['ie' => '869300034336168', 'ic' => '05107060075601073', 'lat' =>  27.826250, 'lng' =>  114.894960, 'name' =>  '同创中央公园','area' => '江西省'],
            ['ie' => '869300034336465', 'ic' => '05107060075601103', 'lat' =>  31.490000, 'lng' =>  117.900000, 'name' =>  '合肥经济生态园林1站'  ,'area' => '合肥市'],
            ['ie' => '869300034354575', 'ic' => '05107060075602914', 'lat' =>  19.991627, 'lng' =>  110.218198, 'name' =>  '海口西线补票站', 'area' => '海南省海口市'],
        ];
        foreach ($areas as $key => $product) {
            $area = \App\Area::firstOrCreate(['name' => $product['area']]);
            $product = \App\Product::create([
                'area_id' => $area->id,
                'name' => $product['name'],
                'ie' => $product['ie'],
                'ic' => $product['ic'],
                'lat' => $product['lat'],
                'lng' => $product['lng'],
            ]);
            $created_at = Carbon::parse($time);
            while ($created_at->lt(now())) {
                factory('App\Record')->create([
                    'product_id' => $product->id,
                    'created_at' => $created_at->toDateTimeString(),
                    'updated_at' => $created_at->toDateTimeString(),
                ]);
                $created_at->addMinutes(10);
            }
        }
    }
}
